﻿
#include "FirstViewController.h"

#include "MapViewController.h"
#include "GeoSearchViewController.h"
#include "PoiSearchViewController.h"
#include "LocationViewController.h"
#include "RouteViewController.h"

FirstViewController::FirstViewController()
{

}

FirstViewController::~FirstViewController()
{

}

void FirstViewController::viewDidLoad()
{
    // Do any additional setup after loading the view from its nib.

	const DSize& viewSize = this->getView()->getFrame().size;
    
	this->setNavigationBarItem(CANavigationBarItem::create(UTF8("高德2D地图")));

	CAButton* mapbt = CAButton::createWithFrame(DRect(viewSize.width * 0.5 - 100 * 0.5, 100, 100, 90), CAButtonTypeRoundedRect);
	mapbt->setTitleForState(CAControlStateAll, UTF8("地图"));
	mapbt->setTitleFontSize(28);
	mapbt->setTitleColorForState(CAControlStateAll, CAColor_black);
	mapbt->addTarget(this, CAControl_selector(FirstViewController::mapBtClicked), CAControlEventTouchUpInSide);
	this->getView()->addSubview(mapbt);

	CAButton* locbt = CAButton::createWithFrame(DRect(viewSize.width * 0.5 - 100 * 0.5, 100 + 90 + 30, 100, 90), CAButtonTypeRoundedRect);
	locbt->setTitleForState(CAControlStateAll, UTF8("定位"));
	locbt->setTitleFontSize(28);
	locbt->setTitleColorForState(CAControlStateAll, CAColor_black);
	locbt->addTarget(this, CAControl_selector(FirstViewController::locBtClicked), CAControlEventTouchUpInSide);
	this->getView()->addSubview(locbt);

	CAButton* ceosearchbt = CAButton::createWithFrame(DRect(viewSize.width * 0.5 - 200 * 0.5, 100 + 90 + 30 + 90 + 30, 200, 90), CAButtonTypeRoundedRect);
	ceosearchbt->setTitleForState(CAControlStateAll, UTF8("正反地理编码"));
	ceosearchbt->setTitleFontSize(28);
	ceosearchbt->setTitleColorForState(CAControlStateAll, CAColor_black);
	ceosearchbt->addTarget(this, CAControl_selector(FirstViewController::geoBtClicked), CAControlEventTouchUpInSide);
	this->getView()->addSubview(ceosearchbt);

	CAButton* poibt = CAButton::createWithFrame(DRect(viewSize.width * 0.5 - 200 * 0.5, 100 + 90 + 30 + 90 + 30 + 90 + 30, 200, 90), CAButtonTypeRoundedRect);
	poibt->setTitleForState(CAControlStateAll, UTF8("POI搜索"));
	poibt->setTitleFontSize(28);
	poibt->setTitleColorForState(CAControlStateAll, CAColor_black);
	poibt->addTarget(this, CAControl_selector(FirstViewController::poiBtClicked), CAControlEventTouchUpInSide);
	this->getView()->addSubview(poibt);

	CAButton* routebt = CAButton::createWithFrame(DRect(viewSize.width * 0.5 - 200 * 0.5, 100 + 90 + 30 + 90 + 30 + 90 + 30 + 90 + 30, 200, 90), CAButtonTypeRoundedRect);
	routebt->setTitleForState(CAControlStateAll, UTF8("路线规划"));
	routebt->setTitleFontSize(28);
	routebt->setTitleColorForState(CAControlStateAll, CAColor_black);
	routebt->addTarget(this, CAControl_selector(FirstViewController::routeBtClicked), CAControlEventTouchUpInSide);
	this->getView()->addSubview(routebt);
	
}

void FirstViewController::viewDidUnload()
{
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

void FirstViewController::mapBtClicked(CAControl* ctrl, DPoint point)
{
	MapViewController* mapViewCtrl = new MapViewController();
	this->getNavigationController()->pushViewController(mapViewCtrl, true);
	mapViewCtrl->release();
}

void FirstViewController::locBtClicked(CAControl* ctrl, DPoint point)
{
	LocationViewController* locView = new LocationViewController();
	this->getNavigationController()->pushViewController(locView, true);
	locView->release();
}

void FirstViewController::geoBtClicked(CAControl* ctrl, DPoint point)
{
	GeoSearchViewController* geoView = new GeoSearchViewController();
	this->getNavigationController()->pushViewController(geoView, true);
	geoView->release();
}

void FirstViewController::poiBtClicked(CAControl* ctrl, DPoint point)
{
	PoiSearchViewController* poiView = new PoiSearchViewController();
	this->getNavigationController()->pushViewController(poiView, true);
	poiView->release();
}

void FirstViewController::routeBtClicked(CAControl* ctrl, DPoint point)
{
	RouteViewController* routeView = new RouteViewController();
	this->getNavigationController()->pushViewController(routeView, true);
	routeView->release();
}
